<template>
  <div class="loginpage">
    <h3 class="title">后台管理系统</h3>
    <!-- 输入框 -->
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span>
            <el-icon style="top: -1px"><avatar /></el-icon> 账号登录
          </span>
        </template>
        <login-account ref="accountRef"></login-account>
      </el-tab-pane>
      <el-tab-pane name="iphone">
        <template #label>
          <span>
            <el-icon style="top: -1px"><iphone /></el-icon> 手机登录
          </span>
        </template>
        <login-iphone ref="iphoneRef"></login-iphone>
      </el-tab-pane>
    </el-tabs>
    <!-- 记住和忘记密码 -->
    <div class="remember">
      <el-checkbox v-model="isRememberMm">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <!-- 登录按钮 -->
    <div>
      <el-button type="primary" class="successbtn" @click="loginBtn"
        >立即登录</el-button
      >
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import loginAccount from './login-account.vue'
import LoginIphone from './login-iphone.vue'
export default defineComponent({
  components: { loginAccount, LoginIphone },
  setup() {
    // boolean 一般以is开头
    const isRememberMm = ref(true) // 是否记住密码
    // InstanceType<typeof loginAccount>这个拿到loginAccount的type类型
    const accountRef = ref<InstanceType<typeof loginAccount>>()
    const iphoneRef = ref<InstanceType<typeof LoginIphone>>()
    // 获取当前的tabs
    const currentTab = ref('account')
    const loginBtn = () => {
      if (currentTab.value === 'account') {
        accountRef.value?.loginAction(isRememberMm.value)
      }
      // else if (currentTab.value === 'iphone') {
      //   iphoneRef.value?.loginAction()
      // }
    }
    return {
      isRememberMm,
      accountRef,
      iphoneRef,
      currentTab,
      loginBtn
    }
  }
})
</script>

<style scoped lang="less">
.loginpage {
  width: 320px;
  margin-bottom: 120px;
  .title {
    text-align: center;
  }
  span i {
    vertical-align: middle;
  }
  .remember {
    display: flex;
    justify-content: space-between;
  }
  .successbtn {
    margin-top: 2px;
    width: 100%;
  }
}
</style>
